<template>
  <el-dialog
    :title="title"
    :visible.sync="show"
    width="1100px"
    append-to-body
    center
  >
    <div class="search-box">
      <el-form label-width="100px" :inline="true">
        <el-form-item label="关键字">
          <el-input v-model="name" />
        </el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
        <el-button type="warning" icon="el-icon-refresh" @click="reset()">重置</el-button>
      </el-form>
    </div>
    <com-table
      v-model="selectRow"
      highlight-current-row
      :data="dataList"
      :columns="columns"
      :total="total"
      @pageChange="pageChange"
    >
      <!-- <template v-slot:name="{row}">
        <a class="com-link" @click="viewDetail(row)">{{ row.name }}</a>
      </template>
      <template v-slot:options="{row}">
        <el-button type="primary" icon="el-icon-edit" size="mini" @click="editBuildUnit(row)">编辑</el-button>
        <el-button type="danger" icon="el-icon-delete" size="mini" @click="delBuildUnit(row)">删除</el-button>
      </template> -->
    </com-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="show = false">取 消</el-button>
      <el-button type="primary" @click="confirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getSupplierInfoList } from '@/api/travellingTraderManage'
export default {
  name: 'SupplierSelectList',
  props: {
    type: {
      type: String,
      default: ''
    },
    showModal: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      name: '',
      dataList: [],
      total: 0,
      pageParams: {
        pageNum: 1,
        pageSize: 10
      },
      selectRow: null,
      columns: [
        {
          label: '编号',
          prop: 'number'
        },
        {
          label: '单位名称',
          prop: 'name'
        },
        {
          label: '省份',
          prop: 'province'
        },
        {
          label: '城市',
          prop: 'city'
        }
      ]
    }
  },
  computed: {
    show: {
      get() {
        return this.showModal
      },
      set(val) {
        this.$emit('update:showModal', val)
      }
    },
    title() {
      const titles = [
        '分包队伍选择',
        '材料供应商选择',
        '设备供应商选择',
        '其他供应商选择'
      ]
      return this.type ? titles[this.type - 1] : ''
    }
  },
  mounted() {
    this.getSupplierInfoList()
  },
  methods: {
    confirm() {
      this.$emit('getSelectedData', this.selectRow)
      this.show = false
    },
    pageChange(data) {
      this.pageParams = data
      this.getSupplierInfoList()
    },
    reset() {
      this.name = ''
      this.getSupplierInfoList()
    },
    search() {
      const params = {
        ...this.pageParams,
        type: this.type,
        name: this.name
      }
      getSupplierInfoList(params).then(res => {
        const { data, total } = res.data || {}
        if (data) {
          this.dataList = data
          this.total = total - 0
        }
      })
    },
    getSupplierInfoList() {
      const params = {
        ...this.pageParams,
        type: this.type
      }
      getSupplierInfoList(params).then(res => {
        const { data, total } = res.data || {}
        if (data) {
          this.dataList = data
          this.total = total - 0
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
